/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package fr.maistre.swarn;

import fr.maistre.edu.swarnentity.bacterie;
import fr.maistre.swarn.Environement;
import fr.maistre.swarn.Goal;
import fr.maistre.swarn.Ressource;

import java.util.ArrayList;
import java.util.List;

/**
 *
 * @author Louis Maistre
 */
public abstract class MitoseEntity extends Reproducer {


	public MitoseEntity(fr.maistre.swarn.DNA DNA, Environement environement,
			Goal goal, ListRessources ressourcesCritiques,
			ListRessources ressources) {
		super(DNA, environement, goal, ressourcesCritiques, ressources);
		// TODO Auto-generated constructor stub
	}
	public MitoseEntity(fr.maistre.swarn.DNA DNA, Environement environement,
			Goal goal, ListRessources ressourcesCritiques) {
		super(DNA, environement, goal, ressourcesCritiques);
		// TODO Auto-generated constructor stub
	}
	protected void reproduce(ListRessources ressourcesNeddedForReproduction){
		 if(haveEnoughtRessources(ressourcesNeddedForReproduction)){
			try {
				 this.removeRessources((this.getReproductionCost()));
				 List<Entity> newBorns = new ArrayList<>();
				 
				 List<ListRessources> legacys = this.ressources.divide(2);
				 List<ListRessources> legacysCritique = this.ressourcesCritiques.divide(2);
		
			      Entity entity1 = this.create(new DNA(DNA.addAllLetterRandom()), environement, goal, legacysCritique.get(0),legacys.get(0));
			      Entity entity2 = this.create(new DNA(DNA.addAllLetterRandom()), environement, goal, legacysCritique.get(1),legacys.get(1));
			 
			      newBorns.add(entity1);
			      newBorns.add(entity2);
			      this.childs.addAll(newBorns);
			      for (Entity e : newBorns) {
					e.start();
				}
			        
			} catch (Exception e) {
				// TODO: handle exception
				//e.printStackTrace();
	
			}
		 }
	 
	       
	}
}
